﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Red.Controls.Converters
{
    public sealed class VisibilityInverter : IValueConverter
    {
        #region IValueConverter implementation

        public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
        {
            Visibility visibility = (Visibility)value;

            switch ( visibility )
            {
                case Visibility.Collapsed:
                case Visibility.Hidden:
                    return Visibility.Visible;

                case Visibility.Visible:
                    return ( parameter == null ) ? Visibility.Collapsed : (Visibility)parameter;
            }

            // Should never reach here
            return null;
        }

        public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture )
        {
            return Convert( value, targetType, parameter, culture );
        }

        #endregion IValueConverter implementation
    }
}
